import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'vue-openlayers示例', icon: 'dashboard' }
    }]
  },
  // 绘制图形
  {
    path: '/draw',
    component: Layout,
    name: 'Draw',
    meta: { title: '绘制图形', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'draw1',
        name: 'Draw1',
        component: () => import('@/views/draw/draw1'),
        meta: { title: '示例1' }
      },
      {
        path: 'draw2',
        name: 'Draw2',
        component: () => import('@/views/draw/draw2'),
        meta: { title: '示例2' }
      },
      {
        path: 'draw3',
        name: 'Draw3',
        component: () => import('@/views/draw/draw3'),
        meta: { title: '示例3' }
      },
      {
        path: 'draw4',
        name: 'Draw4',
        component: () => import('@/views/draw/draw4'),
        meta: { title: '示例4' }
      },
      {
        path: 'draw5',
        name: 'Draw5',
        component: () => import('@/views/draw/draw5'),
        meta: { title: '示例5' }
      },
      {
        path: 'draw6',
        name: 'Draw6',
        component: () => import('@/views/draw/draw6'),
        meta: { title: '示例6' }
      }
    ]
  },
  // 加载地图
  {
    path: '/map',
    component: Layout,
    name: 'Map',
    meta: { title: '加载地图', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'map1',
        name: 'Map1',
        component: () => import('@/views/map/map1'),
        meta: { title: '百度地图' }
      },
      {
        path: 'map2',
        name: 'Map2',
        component: () => import('@/views/map/map2'),
        meta: { title: '谷歌地图' }
      }
    ]
  },
  // 地图控件
  {
    path: '/function',
    component: Layout,
    name: 'Function',
    meta: { title: '地图控件', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'function1',
        name: 'Function',
        component: () => import('@/views/function/function1'),
        meta: { title: '比例尺' }
      },
      {
        path: 'function2',
        name: 'Function',
        component: () => import('@/views/function/function2'),
        meta: { title: '鹰眼' }
      },
      {
        path: 'function3',
        name: 'Function',
        component: () => import('@/views/function/function3'),
        meta: { title: '经纬度' }
      },
      {
        path: 'function4',
        name: 'Function',
        component: () => import('@/views/function/function4'),
        meta: { title: '搜索定位' }
      }
    ]
  },

  // webgl示例
  {
    path: '/drawlines',
    component: Layout,
    name: 'Drawlines',
    meta: { title: '画等势线', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'text01',
        name: 'Drawlines',
        component: () => import('@/views/drawlines/text01'),
        meta: { title: '画等势线' }
      },
      {
        path: 'text02',
        name: 'Drawlines',
        component: () => import('@/views/drawlines/text02'),
        meta: { title: '示例' }
      }
    ]
  },

  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
        meta: { title: 'External Link', icon: 'link' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
